.class public Llt/noframe/gpsfarmguide/utils/AutofitTextView;
.super Landroid/widget/TextView;
.source "AutofitTextView.java"


# instance fields
.field private mMaxLines:I

.field private mMaxTextSize:F

.field private mMinTextSize:F

.field private mPaint:Landroid/text/TextPaint;

.field private mPrecision:F

.field private mSizeToFit:Z


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 2

    .line 42
    invoke-direct {p0, p1}, Landroid/widget/TextView;-><init>(Landroid/content/Context;)V

    const/4 v0, 0x0

    const/4 v1, 0x0

    .line 43
    invoke-direct {p0, p1, v0, v1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->init(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
    .locals 1

    .line 47
    invoke-direct {p0, p1, p2}, Landroid/widget/TextView;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;)V

    const/4 v0, 0x0

    .line 48
    invoke-direct {p0, p1, p2, v0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->init(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    return-void
.end method

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V
    .locals 0

    .line 52
    invoke-direct {p0, p1, p2, p3}, Landroid/widget/TextView;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    .line 53
    invoke-direct {p0, p1, p2, p3}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->init(Landroid/content/Context;Landroid/util/AttributeSet;I)V

    return-void
.end method

.method private static getLineCount(Ljava/lang/String;Landroid/text/TextPaint;FFLandroid/util/DisplayMetrics;)I
    .locals 8

    const/4 v0, 0x0

    .line 342
    invoke-static {v0, p2, p4}, Landroid/util/TypedValue;->applyDimension(IFLandroid/util/DisplayMetrics;)F

    move-result p2

    invoke-virtual {p1, p2}, Landroid/text/TextPaint;->setTextSize(F)V

    .line 344
    new-instance p2, Landroid/text/StaticLayout;

    float-to-int v3, p3

    sget-object v4, Landroid/text/Layout$Alignment;->ALIGN_NORMAL:Landroid/text/Layout$Alignment;

    const/high16 v5, 0x3f800000    # 1.0f

    const/4 v6, 0x0

    const/4 v7, 0x1

    move-object v0, p2

    move-object v1, p0

    move-object v2, p1

    invoke-direct/range {v0 .. v7}, Landroid/text/StaticLayout;-><init>(Ljava/lang/CharSequence;Landroid/text/TextPaint;ILandroid/text/Layout$Alignment;FFZ)V

    .line 346
    invoke-virtual {p2}, Landroid/text/StaticLayout;->getLineCount()I

    move-result p0

    return p0
.end method

.method private static getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F
    .locals 16

    move-object/from16 v8, p1

    move/from16 v9, p2

    move/from16 v10, p3

    add-float v0, p4, p5

    const/high16 v1, 0x40000000    # 2.0f

    div-float v11, v0, v1

    const/4 v12, 0x0

    move-object/from16 v13, p7

    .line 294
    invoke-static {v12, v11, v13}, Landroid/util/TypedValue;->applyDimension(IFLandroid/util/DisplayMetrics;)F

    move-result v0

    invoke-virtual {v8, v0}, Landroid/text/TextPaint;->setTextSize(F)V

    const/4 v14, 0x1

    if-eq v10, v14, :cond_0

    .line 298
    new-instance v15, Landroid/text/StaticLayout;

    float-to-int v3, v9

    sget-object v4, Landroid/text/Layout$Alignment;->ALIGN_NORMAL:Landroid/text/Layout$Alignment;

    const/high16 v5, 0x3f800000    # 1.0f

    const/4 v6, 0x0

    const/4 v7, 0x1

    move-object v0, v15

    move-object/from16 v1, p0

    move-object/from16 v2, p1

    invoke-direct/range {v0 .. v7}, Landroid/text/StaticLayout;-><init>(Ljava/lang/CharSequence;Landroid/text/TextPaint;ILandroid/text/Layout$Alignment;FFZ)V

    .line 300
    invoke-virtual {v15}, Landroid/text/StaticLayout;->getLineCount()I

    move-result v0

    goto :goto_0

    :cond_0
    const/4 v15, 0x0

    const/4 v0, 0x1

    :goto_0
    if-le v0, v10, :cond_1

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move/from16 v2, p2

    move/from16 v3, p3

    move/from16 v4, p4

    move v5, v11

    move/from16 v6, p6

    move-object/from16 v7, p7

    .line 307
    invoke-static/range {v0 .. v7}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F

    move-result v0

    return v0

    :cond_1
    if-ge v0, v10, :cond_2

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move/from16 v2, p2

    move/from16 v3, p3

    move v4, v11

    move/from16 v5, p5

    move/from16 v6, p6

    move-object/from16 v7, p7

    .line 311
    invoke-static/range {v0 .. v7}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F

    move-result v0

    return v0

    :cond_2
    const/4 v1, 0x0

    if-ne v10, v14, :cond_3

    move-object/from16 v2, p0

    .line 317
    invoke-virtual {v8, v2}, Landroid/text/TextPaint;->measureText(Ljava/lang/String;)F

    move-result v0

    goto :goto_2

    :cond_3
    move-object/from16 v2, p0

    :goto_1
    if-ge v12, v0, :cond_5

    .line 320
    invoke-virtual {v15, v12}, Landroid/text/StaticLayout;->getLineWidth(I)F

    move-result v3

    cmpl-float v3, v3, v1

    if-lez v3, :cond_4

    .line 321
    invoke-virtual {v15, v12}, Landroid/text/StaticLayout;->getLineWidth(I)F

    move-result v1

    :cond_4
    add-int/lit8 v12, v12, 0x1

    goto :goto_1

    :cond_5
    move v0, v1

    :goto_2
    sub-float v1, p5, p4

    cmpg-float v1, v1, p6

    if-gez v1, :cond_6

    return p4

    :cond_6
    cmpl-float v1, v0, v9

    if-lez v1, :cond_7

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move/from16 v2, p2

    move/from16 v3, p3

    move/from16 v4, p4

    move v5, v11

    move/from16 v6, p6

    move-object/from16 v7, p7

    .line 329
    invoke-static/range {v0 .. v7}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F

    move-result v0

    return v0

    :cond_7
    cmpg-float v0, v0, v9

    if-gez v0, :cond_8

    move-object/from16 v0, p0

    move-object/from16 v1, p1

    move/from16 v2, p2

    move/from16 v3, p3

    move v4, v11

    move/from16 v5, p5

    move/from16 v6, p6

    move-object/from16 v7, p7

    .line 332
    invoke-static/range {v0 .. v7}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F

    move-result v0

    return v0

    :cond_8
    return v11
.end method

.method private init(Landroid/content/Context;Landroid/util/AttributeSet;I)V
    .locals 5

    .line 57
    invoke-virtual {p1}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v0

    invoke-virtual {v0}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object v0

    iget v0, v0, Landroid/util/DisplayMetrics;->scaledDensity:F

    float-to-int v0, v0

    mul-int/lit8 v0, v0, 0x8

    const/4 v1, 0x1

    const/high16 v2, 0x3f000000    # 0.5f

    if-eqz p2, :cond_0

    .line 63
    sget-object v3, Llt/noframe/gpsfarmguide/R$styleable;->AutofitTextView:[I

    const/4 v4, 0x0

    invoke-virtual {p1, p2, v3, p3, v4}, Landroid/content/Context;->obtainStyledAttributes(Landroid/util/AttributeSet;[III)Landroid/content/res/TypedArray;

    move-result-object p1

    const/4 p2, 0x2

    .line 68
    invoke-virtual {p1, p2, v1}, Landroid/content/res/TypedArray;->getBoolean(IZ)Z

    move-result p2

    .line 69
    invoke-virtual {p1, v4, v0}, Landroid/content/res/TypedArray;->getDimensionPixelSize(II)I

    move-result v0

    .line 71
    invoke-virtual {p1, v1, v2}, Landroid/content/res/TypedArray;->getFloat(IF)F

    move-result v2

    .line 72
    invoke-virtual {p1}, Landroid/content/res/TypedArray;->recycle()V

    goto :goto_0

    :cond_0
    const/4 p2, 0x1

    .line 75
    :goto_0
    new-instance p1, Landroid/text/TextPaint;

    invoke-direct {p1}, Landroid/text/TextPaint;-><init>()V

    iput-object p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    .line 76
    invoke-virtual {p0, p2}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setSizeToFit(Z)V

    .line 77
    invoke-super {p0}, Landroid/widget/TextView;->getTextSize()F

    move-result p1

    invoke-direct {p0, p1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setRawTextSize(F)V

    int-to-float p1, v0

    .line 78
    invoke-direct {p0, p1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setRawMinTextSize(F)V

    .line 79
    invoke-virtual {p0, v2}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setPrecision(F)V

    return-void
.end method

.method private refitText()V
    .locals 9

    .line 241
    iget-boolean v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mSizeToFit:Z

    if-nez v0, :cond_0

    return-void

    .line 245
    :cond_0
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    if-gtz v0, :cond_1

    return-void

    .line 250
    :cond_1
    invoke-virtual {p0}, Landroid/widget/TextView;->getText()Ljava/lang/CharSequence;

    move-result-object v0

    invoke-interface {v0}, Ljava/lang/CharSequence;->toString()Ljava/lang/String;

    move-result-object v1

    .line 251
    invoke-virtual {p0}, Landroid/widget/TextView;->getWidth()I

    move-result v0

    invoke-virtual {p0}, Landroid/widget/TextView;->getPaddingLeft()I

    move-result v2

    sub-int/2addr v0, v2

    invoke-virtual {p0}, Landroid/widget/TextView;->getPaddingRight()I

    move-result v2

    sub-int/2addr v0, v2

    if-lez v0, :cond_7

    .line 253
    invoke-virtual {p0}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

    move-result-object v2

    .line 254
    invoke-static {}, Landroid/content/res/Resources;->getSystem()Landroid/content/res/Resources;

    move-result-object v3

    .line 257
    iget v6, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxTextSize:F

    const/4 v5, 0x0

    if-eqz v2, :cond_2

    .line 262
    invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v3

    .line 264
    :cond_2
    invoke-virtual {v3}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object v8

    .line 266
    iget-object v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    invoke-virtual {p0}, Landroid/widget/TextView;->getPaint()Landroid/text/TextPaint;

    move-result-object v3

    invoke-virtual {v2, v3}, Landroid/text/TextPaint;->set(Landroid/text/TextPaint;)V

    .line 267
    iget-object v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    invoke-virtual {v2, v6}, Landroid/text/TextPaint;->setTextSize(F)V

    .line 269
    iget v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    const/4 v3, 0x1

    if-ne v2, v3, :cond_3

    iget-object v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    invoke-virtual {v2, v1}, Landroid/text/TextPaint;->measureText(Ljava/lang/String;)F

    move-result v2

    int-to-float v3, v0

    cmpl-float v2, v2, v3

    if-gtz v2, :cond_4

    :cond_3
    iget-object v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    int-to-float v3, v0

    .line 270
    invoke-static {v1, v2, v6, v3, v8}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getLineCount(Ljava/lang/String;Landroid/text/TextPaint;FFLandroid/util/DisplayMetrics;)I

    move-result v2

    iget v3, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    if-le v2, v3, :cond_5

    .line 271
    :cond_4
    iget-object v2, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPaint:Landroid/text/TextPaint;

    int-to-float v3, v0

    iget v4, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    iget v7, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPrecision:F

    invoke-static/range {v1 .. v8}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->getTextSize(Ljava/lang/String;Landroid/text/TextPaint;FIFFFLandroid/util/DisplayMetrics;)F

    move-result v6

    .line 275
    :cond_5
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMinTextSize:F

    cmpg-float v1, v6, v0

    if-gez v1, :cond_6

    goto :goto_0

    :cond_6
    move v0, v6

    :goto_0
    const/4 v1, 0x0

    .line 279
    invoke-super {p0, v1, v0}, Landroid/widget/TextView;->setTextSize(IF)V

    :cond_7
    return-void
.end method

.method private setRawMinTextSize(F)V
    .locals 1

    .line 179
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMinTextSize:F

    cmpl-float v0, p1, v0

    if-eqz v0, :cond_0

    .line 180
    iput p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMinTextSize:F

    .line 181
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    :cond_0
    return-void
.end method

.method private setRawTextSize(F)V
    .locals 1

    .line 133
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxTextSize:F

    cmpl-float v0, p1, v0

    if-eqz v0, :cond_0

    .line 134
    iput p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxTextSize:F

    .line 135
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    :cond_0
    return-void
.end method


# virtual methods
.method public getMaxLines()I
    .locals 1

    .line 221
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    return v0
.end method

.method public getMinTextSize()F
    .locals 1

    .line 143
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMinTextSize:F

    return v0
.end method

.method public getPrecision()F
    .locals 1

    .line 190
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPrecision:F

    return v0
.end method

.method public getTextSize()F
    .locals 1

    .line 114
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxTextSize:F

    return v0
.end method

.method protected onSizeChanged(IIII)V
    .locals 0

    .line 358
    invoke-super {p0, p1, p2, p3, p4}, Landroid/widget/TextView;->onSizeChanged(IIII)V

    if-eq p1, p3, :cond_0

    .line 360
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    :cond_0
    return-void
.end method

.method protected onTextChanged(Ljava/lang/CharSequence;III)V
    .locals 0

    .line 352
    invoke-super {p0, p1, p2, p3, p4}, Landroid/widget/TextView;->onTextChanged(Ljava/lang/CharSequence;III)V

    .line 353
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    return-void
.end method

.method public setLines(I)V
    .locals 0

    .line 211
    invoke-super {p0, p1}, Landroid/widget/TextView;->setLines(I)V

    .line 212
    iput p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    .line 213
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    return-void
.end method

.method public setMaxLines(I)V
    .locals 1

    .line 229
    invoke-super {p0, p1}, Landroid/widget/TextView;->setMaxLines(I)V

    .line 230
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    if-eq p1, v0, :cond_0

    .line 231
    iput p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mMaxLines:I

    .line 232
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    :cond_0
    return-void
.end method

.method public setMinTextSize(I)V
    .locals 1

    int-to-float p1, p1

    const/4 v0, 0x2

    .line 175
    invoke-virtual {p0, v0, p1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setMinTextSize(IF)V

    return-void
.end method

.method public setMinTextSize(IF)V
    .locals 2

    .line 156
    invoke-virtual {p0}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

    move-result-object v0

    .line 157
    invoke-static {}, Landroid/content/res/Resources;->getSystem()Landroid/content/res/Resources;

    move-result-object v1

    if-eqz v0, :cond_0

    .line 160
    invoke-virtual {v0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v1

    .line 163
    :cond_0
    invoke-virtual {v1}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object v0

    invoke-static {p1, p2, v0}, Landroid/util/TypedValue;->applyDimension(IFLandroid/util/DisplayMetrics;)F

    move-result p1

    invoke-direct {p0, p1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setRawMinTextSize(F)V

    return-void
.end method

.method public setPrecision(F)V
    .locals 1

    .line 200
    iget v0, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPrecision:F

    cmpl-float v0, p1, v0

    if-eqz v0, :cond_0

    .line 201
    iput p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mPrecision:F

    .line 202
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    :cond_0
    return-void
.end method

.method public setSizeToFit(Z)V
    .locals 0

    .line 105
    iput-boolean p1, p0, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->mSizeToFit:Z

    .line 106
    invoke-direct {p0}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->refitText()V

    return-void
.end method

.method public setTextSize(IF)V
    .locals 2

    .line 122
    invoke-virtual {p0}, Landroid/widget/TextView;->getContext()Landroid/content/Context;

    move-result-object v0

    .line 123
    invoke-static {}, Landroid/content/res/Resources;->getSystem()Landroid/content/res/Resources;

    move-result-object v1

    if-eqz v0, :cond_0

    .line 126
    invoke-virtual {v0}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

    move-result-object v1

    .line 129
    :cond_0
    invoke-virtual {v1}, Landroid/content/res/Resources;->getDisplayMetrics()Landroid/util/DisplayMetrics;

    move-result-object v0

    invoke-static {p1, p2, v0}, Landroid/util/TypedValue;->applyDimension(IFLandroid/util/DisplayMetrics;)F

    move-result p1

    invoke-direct {p0, p1}, Llt/noframe/gpsfarmguide/utils/AutofitTextView;->setRawTextSize(F)V

    return-void
.end method
